<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .red {
      color: red;
    }
  </style>
</head>

<body>

  <div id="app">
    <!-- 1. 使用动态绑定变量 -->
    <h3 :class="activate">{{ message }}</h3>

    <!-- 2. 绑定对象: 对象语法 -->
    <h3 :class="{red: isActivate, line: isActivate}">我会变颜色</h3>
    <!-- 放入类中 -->
    <h3 :class="getClassName()">我会变颜色</h3>
    <button @click="btnClick">变色按钮</button>

    <!-- 3. 绑定数组: 数组语法 -->
    <h3 :class="classNameList">我不会变颜色</h3>

  </div>

  <script src="../../js/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        message: 'hello',
        isActivate: false,
        activate: 'red',
        classNameList: ['red', 'line']
      },

      methods: {
        btnClick: function () {
          this.isActivate = !this.isActivate;
        },

        // 获取类名
        getClassName: function () {
          return { red: this.isActivate, line: this.isActivate };
        }
      }
    })
  </script>
</body>

</html>